using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using WindowsGame.Common.Inputs.Types;
using WindowsGame.Common.Interfaces;
using WindowsGame.Common.Static;

namespace WindowsGame.Common .Inputs
{
	public class FoneInputFactory : BaseInputFactory, IInputFactory
	{
		public FoneInputFactory(IJoystickInput joystickInput, ITouchScreenInput touchScreenInput)
		{
			JoystickInput = joystickInput;
			TouchScreenInput = touchScreenInput;
		}

		public override void Initialize()
		{
			TouchScreenInput.Initialize();
		}

		public void Update(GameTime gameTime)
		{
			JoystickInput.Update(gameTime);
			TouchScreenInput.Update(gameTime);
		}

		public override Direction HoldDirection()
		{
#if ANDROID
			Direction holDirection = base.HoldDirection();
			if (Direction.None != holDirection)
			{
				return holDirection;
			}
#endif
			if (TouchLocationState.Pressed != TouchScreenInput.TouchState)
			{
				return Direction.None;
			}

			return MoveDirection();
		}
		public override Direction MoveDirection()
		{
#if ANDROID
			Direction moveDirection = base.MoveDirection();
			if (Direction.None != moveDirection)
			{
				return moveDirection;
			}
#endif
			if (Vector2.Zero == TouchScreenInput.TouchPosition)
			{
				return Direction.None;
			}

			return Direction.None;
		}

		public Boolean Escape()
		{
			return JoystickInput.JoyMove(Buttons.Back);
		}
		public Boolean Start()
		{
			return TouchLocationState.Pressed == TouchScreenInput.TouchState;
			//return TouchScreenInput.Tap;
		}
		public Boolean Reset()
		{
			return TouchScreenInput.DoubleTap;
		}

		public override void SetMotors(float leftMotor, float rightMotor)
		{
		}
		public override void ResetMotors()
		{
		}

	}
}